
#pragma once

#include "Server/ServerType.h"
#include "wch/StringTokenizer.h"
using namespace wch;

struct DBConfig
{
	std::string _name;
	std::string	_host;
	UInt16		_port;
	std::string _user;
	std::string	_passwd;

	DBConfig() : _port(0) {}
};

class Cfg
{
public:
	Cfg();
	bool load(const std::string&);

public:
	inline void setTcpPort(UInt16 p)				{ _tcpPort = p; }
	inline void setDataDatabase(const char * ip, UInt16 port, const char * user, const char * pwd, const char * db)
	{
		_dataConf._host = ip;
		_dataConf._port = port;
		_dataConf._user = user;
		_dataConf._passwd = pwd;
		_dataConf._name = db;
	}
	inline void setPlatDatabase(const char * ip, UInt16 port, const char * user, const char * pwd, const char * db)
	{
		_platConf._host = ip;
		_platConf._port = port;
		_platConf._user = user;
		_platConf._passwd = pwd;
		_platConf._name = db;
	}
	inline void setObjectDatabase(const char * ip, UInt16 port, const char * user, const char * pwd, const char * db)
	{
		_objectConf._host = ip;
		_objectConf._port = port;
		_objectConf._user = user;
		_objectConf._passwd = pwd;
		_objectConf._name = db;
	}

	inline void setHttpPort(UInt16 port)
	{
		_httpPort = port;
	}


	inline void setFree(UInt8 free) { _free = free > 0; }
	inline void setReportPath(const char * path) { _reportPath = path; }
	inline std::string getReportPath()	{ return _reportPath; }

	inline DBConfig getDataConfig() { return _dataConf; }
	inline DBConfig getPlatConfig() { return _platConf; }
	inline DBConfig getObjectConfig() { return _objectConf; }

	inline UInt16 getTcpPort() { return _tcpPort; }

	inline UInt16 getHttpPort()	{ return _httpPort; }

public:
	UInt16	 _tcpPort;
	DBConfig _dataConf;
	DBConfig _platConf;
	DBConfig _objectConf;

	UInt16	 _httpPort;

	std::string _reportPath;

private:
	std::string _file;

public:
	bool _free;
};

extern Cfg cfg;